<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="com.gpstracking.BL.DispositivoBL"%>
<%@page import="com.gpstracking.BE.Dispositivo"%>

<%@page import="com.gpstracking.BL.CondicionBL"%>
<%@page import="com.gpstracking.BE.Condicion"%>

<%@page import="com.gpstracking.BL.NotificacionBL"%>
<%@page import="com.gpstracking.BE.Notificacion"%>



<%@page import="com.gpstracking.BE.Evento"%>
<%@page import="com.gpstracking.BE.NotificacionDispositivo"%>
<%@page import="com.gpstracking.BE.NotificacionCondicion"%>
<%@ page import="com.gpstracking.BE.Usuario" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> 

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<meta charset="UTF-8" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<meta name="author" content="" />
		
		  <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { 
      	height: 700px;
      	width: 1440px;
      	position: relative; 
       }
    </style>
    <script type="text/javascript"
    	src="http://maps.googleapis.com/maps/api/js?key=AIzaSyC5S9soHyeEA9TCIfxAGUo3fOqJfTh4eFk&sensor=false">
    </script>
    <script type="text/javascript"  
    	src="./js/geometry.js" >
    </script>
        
    <script type="text/javascript"
      	src="./js/maps.js" >
    </script>
      <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
    
    <script type="text/javascript" src="./js/ajaxCom.js"></script>
   
		
		<!--========= STYLES =========-->
		<link rel="stylesheet" href="../css/reset.css" />
		<link rel="stylesheet" href="../css/grid.css" />
		<link rel="stylesheet" href="../css/uniform.default.css" />
		<link rel="stylesheet" href="../css/chosen.css" />
		<link rel="stylesheet" href="../plugins/jqueryui/all/themes/base/jquery.ui.all.css" />
		<link rel="stylesheet" href="../plugins/alerts/resources/css/jquery.toastmessage.css" />
		<link rel="stylesheet" href="../plugins/datatables/media/css/demo_page.css" />
		<link rel="stylesheet" href="../plugins/datatables/media/css/demo_table_jui.css" />
		
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/config.css" />
		<!--[if gte IE 8]><link rel="stylesheet" href="css/ie8.css" /><![endif]-->
		
		<!--============ JQUERY =============-->
		<script src="../js/jquery.js" type="text/javascript"></script>
		<script src="../js/jquery.uniform.js" type="text/javascript"></script>
		<script src="../js/chosen.jquery.js" type="text/javascript"></script>
		<script src="../js/jquery.placeholder.js" type="text/javascript"></script>
		
		<script src="../plugins/jqueryui/all/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
		<script src="../plugins/alerts/javascript/jquery.toastmessage.js" type="text/javascript"></script>
		<script src="../js/scriptbreaker-multiple-accordion-1.js" type="text/javascript" ></script>
		<script src="../plugins/datatables/media/js/jquery.dataTables.js" type="text/javascript" ></script>
		<script src="../js/head_scripts.js" type="text/javascript"></script>
		
		<script src="../js/controller/notificaciones.js" type="text/javascript"></script>
	
						
		<!--=== ENABLE HTML5 TAGS FOR IE ===-->
		<!--[if IE]><script src="js/html5.js"></script><![endif]-->
		
		<title>GPS Tracking</title>
	</head>
	
	<%
		Usuario user = (Usuario)session.getAttribute("user");
		
		DispositivoBL dispositivoBL = new DispositivoBL();
		CondicionBL condicionBL = new CondicionBL();
		NotificacionBL notificacionBL = new NotificacionBL();
		
		
		List<Dispositivo> dispositivosActivos = dispositivoBL.activos(user);
		List<Condicion> condicionesActivas = condicionBL.getCondicionesActivas(user);
		List<Notificacion> notificacionesActivas = notificacionBL.getNotificacionesActivas(user); 
	
	%>

	<body onload="initialize()">
		<jsp:include page="../static/sidebar.jsp" />
		
		
		<section class="container">
			
			
			
			<section class="container_12">
				<section id="page_content" class="page_content">
					<jsp:include page="../static/toppanel.jsp" />				
					
					
					
					<div class="grid_12">
						<div class="box">
							<h2>
								Notificaciones
								<span class="l"></span><span class="r"></span>
							</h2>
							<div class="block">
								<div class="block_in">
									<!-- BEGIN TABLE -->
									<table class="display basictable">
										<thead>
											<tr>
												<th>Codigo</th>
												<th>Nombre</th>
												<th>Dispositivos</th>
												<th>Condiciones</th>
											</tr>
										</thead>
										<tbody>
											<% for( Notificacion notificacion : notificacionesActivas ){  
												List<String> dispositivos = new ArrayList<String>();
												List<String> condiciones = new ArrayList<String>();
												
												Set s_nd = notificacion.getNotificacionDispositivos();
												Set s_nc = notificacion.getNotificacionCondicions();
												
												
												Iterator it_d = s_nd.iterator();
												Iterator it_c = s_nc.iterator();
												
												while (it_d.hasNext()) {
													NotificacionDispositivo e = (NotificacionDispositivo) it_d.next(); 
												    dispositivos.add(e.getDispositivo().getNombre());
												}

												while (it_c.hasNext()) {
													NotificacionCondicion e = (NotificacionCondicion) it_c.next(); 
												    condiciones.add(e.getCondicion().getNombre());
												}
											
											%>
												<tr class="gradeX">
													<td><% out.print("NOT" + notificacion.getIdNotificacion()); %></td>
													<td><% out.print(notificacion.getNombre()); %></td>
													<td><% out.print(dispositivos.toString()); %></td>
													<td><% out.print(condiciones.toString()); %></td>
												</tr>
											<% } %>
										
										</tbody>
									</table>
									<!-- END TABLE -->
								</div>
							</div>
						</div>
					</div> <!-- End of .grid_12 -->
					<div class="clear"></div>
					
					
					<div class="grid_12">
						<div class="box">
							<div class="block">
								<div class="box">
									<h2>
										Nueva notificacion 
										<span class="l"></span><span class="r"></span>
									</h2>
									<div class="hide"><span class="s">+</span><span class="h">-</span></div>
								</div>
									<div class="block">									
											<form class="form_place" id="notificacion" style="width=700px" method="post" onsubmit="return sendNotificacion();">
												<section class="form_row">
													<div class="grid_2"><label>Nombre:</label></div>
													<div class="grid_10">
														<div class="block_content">
															<input type="text" name="nombre" id="nombre" class="input20pc" required="required" />
														</div>
													</div>
													<div class="clear"></div>
												</section>
											
												<section class="form_row">
													<div class="grid_2"><label>Descripción sobre la notificacion:</label></div>
													<div class="grid_10">
														<div class="block_content">
															<input type="text" name="descripcion" id="descripcion" class="input50pc" required="required" />
														</div>
													</div>
													<div class="clear"></div>
												</section>
												
												
												<section class="form_row">
												<div class="grid_2"><label>Asociar dispositivos</label></div>
												<div class="grid_10">
													<div class="block_content">
														<select id="lstdispositivos" data-placeholder="Elija dispositivos" style="width:350px;" class="chzn-select" multiple tabindex="4">
														  <option value=""></option>
														  <optgroup label="Dispositivos">
														  		<% for( Dispositivo it : dispositivosActivos){ %>
														  				<option value="<% out.print(it.getIdDispositivo()); %>"> <% out.print(it.getNombre()); %> </option> 
													  			<% } %>
														  </optgroup>
														  
														</select>
													</div>
												</div>
												<div class="clear"></div>
											</section>
														
												
												<section class="form_row">
												<div class="grid_2"><label>Asociar condiciones</label></div>
												<div class="grid_10">
													<div class="block_content">
														<select id="lstcondiciones" data-placeholder="Elija condiciones" style="width:350px;" class="chzn-select" multiple tabindex="4">
														  <option value=""></option>
														  <optgroup label="Condiciones">
															<% for( Condicion it : condicionesActivas){ %>
														  				<option value="<% out.print(it.getIdCondicion()); %>"> <% out.print(it.getNombre()); %> </option> 
													  			<% } %>
														  </optgroup>
														  
														</select>
													</div>
												</div>
												<div class="clear"></div>
											</section>
												
												
													<section class="form_row">
													<div class="clear"></div>
													</section>
												<section class="form_row">
												<div class="grid_10 alignright">
														<div class="block_content">
															<input class="button blue medium submit alignleft" type="submit" value="Registrar" />
															<input class="button red medium submit alignleft" type="reset" value="Rehacer" />															
														</div>
													</div>
													<div class="clear"></div>
												</section>
											</form>
											
									</div>
								</div>
							</div>
						</div>
					</div><!-- End of grid_12 -->
					
					<div class="clear"></div>
				</section><!-- end of #page_content -->
			</section><!-- end of #container_12 -->
		</section><!-- end of #container -->
		
	<script src="../js/ui_calls.js" type="text/javascript"></script>
	<script src="../js/scripts.js" type="text/javascript"></script>
	</body>

</html>
